#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 1e5 + 10, M = 2 * N;
int h[N], ne[M], e[M], w[M], idx;
int n;
int dis[N];
void add(int a, int b, int v)
{
	e[idx] = b;
	w[idx] = v;
	ne[idx] = h[a];
	h[a] = idx++;
}
void dfs(int u, int father, int v)
{
	dis[u] = v;
	for (int i = h[u]; ~i; i = ne[i]) {
		int j = e[i];
		if (j != father) {
			dfs(j, u, w[i] + v);
		}
	}
}
int main()
{
	cin >> n;
	memset(h, -1, sizeof(h));
	for (int i = 0; i < n - 1; i++) {
		int a, b, w;
		cin >> a >> b >> w;
		add(a, b, w);
		add(b, a, w);
	}
	dfs(1, -1, 0);
	int t = 1;
	for (int i = 1; i <= n; i++) {
		if (dis[i] > dis[t]) {
			t = i;
		}
	}
	dfs(t, -1, 0);
	for (int i = 1; i <= n; i++) {
		if (dis[i] > dis[t]) {
			t = i;
		}
	}
	LL s = dis[t];
	LL ans = 10 * s + s * (s + 1) / 2;
	cout << ans << endl;
	return 0;
}